package com.qingxin.wuye.repertory.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qingxin.store.bean.ChartData;
import com.qingxin.sys.action.BaseAction;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.utils.StringUtils;
import com.qingxin.wuye.repertory.entity.Repertory;
import com.qingxin.wuye.repertory.service.GiService;
import com.qingxin.wuye.repertory.service.RepertoryService;

@Controller
@RequestMapping("/gi")
public class GiAction extends BaseAction{
	@Autowired
	private GiService giService;
	@Autowired
	private RepertoryService repertoryService;
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/getXltjData.json" , method={RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object getXltjData(String repertoryid,HttpServletRequest request){
		if(StringUtils.isEmpty(repertoryid)){
			return Collections.EMPTY_MAP;
		}
		Repertory repertory = repertoryService.get(repertoryid);
		if(repertory == null){
			return Collections.EMPTY_MAP;
		}
		
		Map<String, Object> rsMap = (Map<String, Object>) giService.getQjdXltjData(repertoryid);
		
		return rsMap;
	}
	
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/list.do", method=RequestMethod.GET)
	public String index(ModelMap model , HttpServletRequest request) {
		List<Repertory> repertoryrs = new ArrayList<>();
		repertoryrs = repertoryService.listByHql("from Repertory order by name asc");
		model.put("repertoryrs", repertoryrs);
		return "wuye/gi/xltj_all";
	}
	
	
	@RequestMapping(value="/listdata.json" , method={RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object listdata(String searchname,String repertoryid,PageParam pageParam, HttpServletRequest request){
		return giService.list(searchname,repertoryid, pageParam, getLoginUser(request));
	}
	
}
